#include "stdio.h"
#include "stdlib.h"

#define STACK_INIT_SIZE 100
#define STACKIN 10

typedef int SElemType;
// 定义返回状态
#define TRUE 1
#define FALSE 0
typedef int Status;

// 定义栈数据结构
typedef struct
{
    SElemType *base;
    SElemType *top;
    int stacksize;
} SqStack;

// 栈的初始化
Status InitStack(SqStack *S)
{
    S->base = (SElemType *)malloc(STACK_INIT_SIZE * sizeof(SElemType));
    S->base = S->top;
    S->stacksize = STACK_INIT_SIZE;
    return TRUE;
}
// 返回栈顶元素
SElemType GetTop(SqStack *S)
{
    if (S->top == S->base)
        return FALSE;
    SElemType e = *(S->top - 1);
    return e;
}
// 插入e元素入栈
Status insertStack(SqStack *S, SElemType e)
{
    // 判断栈是否满(不考虑增量问题)
    if (S->top - S->base >= S->stacksize)
        return FALSE;
    *S->top++ = e;
    /*
        *S->top=e;
        S->top++;
    */
    return TRUE;
}
// 出栈(删除栈顶元素)
SElemType DeleteStack(SqStack *S)
{
    if (S->top == S->base)
        return FALSE;
    return *--S->top;
}

int main()
{
    // 创建一个栈
    SqStack S;
    InitStack(&S);
    insertStack(&S, 1);
    SElemType e;
    e = GetTop(&S);
    printf("%d", e);

    insertStack(&S, 2);
    e = GetTop(&S);
    printf("%d", e);

    insertStack(&S, 3);
    e = GetTop(&S);
    printf("%d", e);

    insertStack(&S, 4);
    e = GetTop(&S);
    printf("%d", e);

    e = DeleteStack(&S);
    printf("%d", e);

    e = GetTop(&S);
    printf("%d", e);
}
